package com.exam.controller;
import com.exam.entity.DataDictionary;
import com.exam.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/data-dictionaries")
public class DataDictionaryController {
//数据字典增删改查
    @Autowired
    private DataDictionaryService dataDictionaryService;

    @PostMapping
    public ResponseEntity<DataDictionary> createDataDictionary(@RequestBody DataDictionary dataDictionary) {
        DataDictionary createdDataDictionary = dataDictionaryService.createDataDictionary(dataDictionary);
        return new ResponseEntity<>(createdDataDictionary, HttpStatus.CREATED);
    }
//调用服务层的方法来创建数据字典。
//返回状态码HttpStatus.CREATED，表示资源已成功创建。
    @PutMapping("/{id}")
    public ResponseEntity<DataDictionary> updateDataDictionary(@PathVariable Long id, @RequestBody DataDictionary dataDictionary) {
        DataDictionary updatedDataDictionary = dataDictionaryService.updateDataDictionary(id, dataDictionary);
        return new ResponseEntity<>(updatedDataDictionary, HttpStatus.OK);
    }
//调用服务层的方法来更新数据字典。
//返回状态码HttpStatus.OK，表示资源已成功更新。
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteDataDictionary(@PathVariable Long id) {
        dataDictionaryService.deleteDataDictionary(id);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
//调用服务层的方法来删除数据字典。
//返回状态码HttpStatus.NO_CONTENT，表示资源已成功删除。
    @GetMapping("/{id}")
    public ResponseEntity<DataDictionary> getDataDictionary(@PathVariable Long id) {
        DataDictionary dataDictionary = dataDictionaryService.getDataDictionary(id);
        return new ResponseEntity<>(dataDictionary, HttpStatus.OK);
    }
    //调用服务层的方法来获取数据字典。
   //返回状态码HttpStatus.OK，表示资源已成功获取。
    @GetMapping
    public ResponseEntity<List<DataDictionary>> getAllDataDictionaries() {
        List<DataDictionary> dataDictionaries = dataDictionaryService.getAllDataDictionaries();
        return new ResponseEntity<>(dataDictionaries, HttpStatus.OK);
    }
//调用服务层的方法来获取所有数据字典。
//返回状态码HttpStatus.OK，表示资源已成功获取。
}